<?php
include_once 'dbinfo.php';
$link = mysqli_connect($dbhost,$dbusername,$dbpassword,$dbname,$dbport);
if(!$link){
    echo "连接失败";
    die;
}
mysqli_set_charset($link,'utf8');

$username = $_POST['username'];
$passwd = $_POST['passwd'];
$photo = $_FILES['photo']['tmp_name'];

$sql = "select * from tb_user where username='$username'";

$result = mysqli_query($link,$sql) ;   

if(mysqli_num_rows($result) > 0){
    die('fail');
}

$filename = md5($photo).$_FILES['photo']['name'];

move_uploaded_file($photo,'../img/'.$filename);

$sql = "insert into tb_user (username,passwd,avatar,role,cellphone)
         values('$username','$passwd','$filename','user',null)";

mysqli_query($link,$sql) ;        

mysqli_close($link);

echo '请确认你的信息:</br>';
echo "用户名：$username</br>";
echo "密码：$passwd</br>";
echo "头像：<img src='../img/$filename' width=100/> </br>";
echo "<a href='../html/login.html'>点击登录</a>";
?>